﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyDDD.AdminModule.Application.QueriesSysAdminRole
{
    public record SysAdminRoleGetMenuIdsQuery : IQuery<Guid[]>
    {
        public Guid Id { get; set; }
    }

    public class SysAdminRoleGetMenuIdsQueryHandler(
        //IMapper mapper,
        Records.SysAdminRoleRecords records,
        ILogger<SysAdminRoleGetMenuIdsQueryHandler> logger)
        : IQueryHandler<SysAdminRoleGetMenuIdsQuery, Guid[]>
    {
        public async Task<Guid[]> Handle(SysAdminRoleGetMenuIdsQuery request, CancellationToken cancellationToken)
        {
            logger.LogDebug("查询 SysAdminRoleGetMenuIdsQueryHandler");
            var query = records.AsQueryable();
            return await query.Include(e => e.MenuList).Where(e => e.Id == request.Id)
                .SelectMany(e => e.MenuList.Select(f => f.SysMenuId)).ToArrayAsync();
        }
    }
}
